package main

import (
	"fmt"
	"gitee.com/wayjin/fabric-extension/contract"
)

type RentAggrement struct {
	PartA  string
	PartB  string
	Deposit int
}

type Landlord struct {
}

type Tenant struct {
}

func (land Landlord) MemberID() string {
	return "Org1MSP"
}

func (tenant Tenant) MemberID() string {
	return "Org2MSP"
}

func (c RentAggrement) Initiate(ctx contract.Context) contract.Response {
	// check if it is A part
	ctx.PutAsset("", c)
	return ctx.Success(nil)
}

func (c RentAggrement) View(ctx contract.Context) contract.Response {
	// only householder and tenant can view the contract
	contractNo, err := ctx.GetStringArg("no")
	if err != nil {
		return ctx.Error(err)
	}
	err = ctx.GetAsset(contractNo, &c)
	if err != nil {
		return ctx.Error( err)
	}
	return ctx.Success(nil)
}

func (c RentAggrement) Confirm(ctx contract.Context) contract.Response {
	return ctx.Success(nil)
}

func main() {
	contract := contract.Contract{
		Participants: map[string]contract.Participant{
			"partA": Landlord{},
			"partB": Tenant{},
		},
		Asset:        map[string]contract.Asset{
			"rent": RentAggrement{},
		},
	}
	if err := contract.Deploy(); err != nil {
		fmt.Println("deploy error: ", err)
	}
}